GBML manual / Motion

move_wrap

Wraps this instance to the opposite edge of the given rectangle (typically the room’s own bounds) once it leaves it by more than margin.

Syntax

move_wrap(left, top, right, bottom, margin = 0)

Arguments

NameType
leftreal
topreal
rightreal
bottomreal
marginreal (can be left out; then it is 0)

Returns

Nothing.

Description

Wraps this instance to the opposite edge of the given rectangle - typically the room's own bounds - once it leaves it by more than margin (leave it out for 0). The classic Asteroids-style screen wrap, applied to whatever rectangle is passed in rather than always the current room automatically.

left, top, right and bottom are places in the room, counted from the room's top-left corner (the same way x and y are). So 0, 0, room_width(), room_height() is the whole room.

This is wrap (Maths) applied to this instance's own position on both axes at once, with a margin a position wrap can use but a plain value wrap has no reason to. Reach for move_wrap when the thing wrapping is self's own x/y; reach for wrap when it is any other number - a menu index, a counter of your own.

Example

move_wrap(0, 0, room_width(), room_height(), 8);

Wraps the walker to the opposite edge of the room once it leaves it by more than 8 pixels - from the room's top-left corner (0, 0) to its bottom-right corner (room_width(), room_height()), the room's own full footprint.

A real capture - the walker approaching the rectangle's own right edgeA real capture - the walker approaching the rectangle's own right edge
A real capture - the walker approaching the rectangle's own right edge
The same walker after crossing the edge - wrapped to the opposite side, the left edge of the same rectangleThe same walker after crossing the edge - wrapped to the opposite side, the left edge of the same rectangle
The same walker after crossing the edge - wrapped to the opposite side, the left edge of the same rectangle

On the GBA

margin can be left out: move_wrap(0, 0, room_width(), room_height()) is the same as passing 0 for it. This is wrap (Maths) applied to a position instead of an arbitrary value, on both axes at once, with a margin an ordinary value wrap has no use for - reach for move_wrap when the thing wrapping is this instance’s own x/y against a rectangle, and for wrap when it is any other number (a menu index, a counter of your own).

See also: move_towrap